/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-03-20
 * Time: 11:32
 */

//父类
class Animal {
    public String name;

    // 父类的无参构造方法
    public Animal() {
        System.out.println("父类的无参构造方法被调用");
    }

    // 父类的有参构造方法
    public Animal(String name) {
        this.name = name;
        System.out.println("父类的有参构造方法被调用, " + "name:" + name);
    }
}
//子类
class Dog extends Animal {
    public int age;
    public Dog() {
        //super(); // 默认会调用父类的无参构造方法，可写可不写，用户没有写时,编译器会自动添加
        System.out.println("子类无参构造方法被调用");
    }

    // 子类的有参构造方法
   public Dog(String name, int age) {
        super(name);//如果没有这个语句调用dog2对象时就默认调用父类无参构造函数，输出父类的无参构造方法被调用
        this.age = age;
        System.out.println("子类有参构造方法被调用," + "age:" + age);
    }

    public Dog(int age) {
        this.age = age;
        System.out.println("子类构造方法二");
    }
}
